<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>修改系统管理员</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">

    <link rel="stylesheet" href="/static/admin/plugins/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="/static/admin/plugins/font-awesome/css/font-awesome.min.css">
</head>

<body>
<div style="margin: 15px;">
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>修改系统管理员</legend>
    </fieldset>

    <form class="layui-form" style="width:800px;" action="/admin/manager/edit" id="addForm">
        <input type="hidden" name="id" value="{$manager.id}">
        <div class="layui-form-item">
            <label class="layui-form-label">登录名</label>
            <div class="layui-input-block">
                <input type="text" name="username" lay-verify="alphnum" autocomplete="off" placeholder="请输入登录名" class="layui-input" maxlength="20" value="{$manager.username}">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">真实姓名</label>
            <div class="layui-input-block">
                <input type="text" name="real_name" lay-verify="required" autocomplete="off" placeholder="请输入真实姓名" class="layui-input" maxlength="20" value="{$manager.real_name}">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">密码</label>
            <div class="layui-input-block">
                <input type="text" name="password" lay-verify="required" autocomplete="off" placeholder="请输入密码" class="layui-input" maxlength="20">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">角色</label>
            <div class="layui-input-block">
                <select name="typeid" lay-verify="required" lay-filter="typeid" id="juese" >
                    <option value="">请选择一个角色</option>
                    {foreach name="roles" item="v"}
                        <option value="{$v.id}" {if condition="$manager.typeid == $v.id"}selected{/if}>{$v.rolename}</option>
                    {/foreach}
                </select>
            </div>
        </div>

        <div style="display: none" id="send">
            <div class="layui-form-item">
                <label class="layui-form-label">配送站名称</label>
                <div class="layui-input-block">
                    <input type="hidden" name='send_id' value="{$send.id}">
                    <input type="text" name="send_name" id="send_name"  value="{$send.send_name}" autocomplete="off"  class="layui-input" maxlength="20">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">城市</label>

                <div class="layui-inline " style="margin-left:20px">
                    <select name="provice_id" lay-verify="" lay-search lay-filter="provice" id="provice_id">
                        {foreach name="provice" item="v"}
                        <option value="{$v.id}" {if condition="$send.provice_id==$v.id"}selected{/if}>{$v.name}</option>
                        {/foreach}
                    </select>
                </div>
                <div class="layui-inline">
                    <select name="city_id" lay-verify="" lay-search id="city_id">
                        {foreach name="city" item="v"}
                        <option value="{$v.id}" {if condition="$send.city_id==$v.id"}selected{/if}>{$v.name}</option>
                        {/foreach}
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">详细地址</label>
                <div class="layui-input-block">
                    <input type="text" name="address"  id="address" value="{$send.address}" autocomplete="off"  class="layui-input" maxlength="20">
                </div>
            </div>


            <div class="layui-form-item">
                <label class="layui-form-label">默认配送站</label>
                <div class="layui-input-block">
                    <input type="radio" name="is_default"  value="0" title="否"  class="layui-input" {if condition="$send.is_default==0"}checked{/if}>
                    <input type="radio" name="is_default"  value="1" title="是"  class="layui-input" {if condition="$send.is_default==1"}checked{/if}>
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-block">
                <input type="radio" name="status" value="1" title="正常" {if condition="$manager.status == 1"}checked{/if}>
                <input type="radio" name="status" value="2" title="禁用" {if condition="$manager.status == 2"}checked{/if}>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" lay-filter="demo">立即提交</button>
                <a class="layui-btn layui-btn-primary" href="/admin/manager/index">返回上一页</a>
            </div>
        </div>
    </form>
</div>
<script type="text/javascript" src="/static/admin/js/jquery.min.js"></script>
<script type="text/javascript" src="/static/admin/plugins/layui/layui.js"></script>
<script>

    layui.use(['form'], function () {
        var form = layui.form(),
                layer = layui.layer;

        //自定义验证规则
        form.verify({
            alphnum:  function(value){
                if(value == ''){
                    return '登录名不能为空';
                }
                if(!/^[0-9a-zA-Z]*$/.test(value)){
                    return '登录名只能是数字和字母';
                }
            }
        });
        //监听提交
        form.on('submit(demo)', function(data) {
            var url = $(data.form).attr('action');
            $.ajax({
                type: "POST",
                url: url,
                data:  data.field,
                async: true,
                beforeSend: function () {
                    jz = layer.load(0, {shade: false}); //0代表加载的风格，支持0-2
                },
                error: function (request) {
                    layer.close(jz);
                    layer.alert('网络错误',{icon:2}, function(index){
                        layer.close(index);
                    });
                },
                success: function (data) {
                    //关闭加载层
                    layer.close(jz);
                    if (data.code == 1) {
                        layer.msg(data.msg, {
                            icon: 1,
                            time: 1500
                        }, function(){
                            window.location.href = data.data.url;
                        });
                    } else if(data.code == -1){
                        window.location.href = '/admin/login/login';
                    }else {
                        layer.alert(data.msg);
                    }
                }
            });
            return false;
        });

        form.on('select(provice)', function(data) {
            $.post('/admin/json_type/getCitys', {provice:data.value}, function(response){;
                var text='';
                for(var i in response.data[0]){
                    text +=
                            '<option value="'+response.data[0][i].id+'">'+response.data[0][i].name+'</option>';
                }
                $('select[name=city_id]').html(text);
                form.render();
            });

        });

        form.on('select(typeid)',function (data) {
            if(data.value==16){
                $('#send').show();
            }else {
                $('#send').hide();
            }
        })
    });

    $(function(){
        var val=$('#juese').val();
        if(val==16){
            $('#send').show();
        }
    })


</script>
</body>

</html>